<template>
  <div class="head">
    <h1>
      <!-- manager -->
      <img src="../../assets/logo.png" alt="">
      manager
    </h1>
    <el-dropdown @command="handleCommand">
      <span class="el-dropdown-link">
        {{userInfo.nickName || userInfo.username || '未读取到用户名'}}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="logout">退出登陆</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";

export default {
  computed: {
    ...mapGetters(["userInfo"])
  },
  methods: {
    ...mapActions(["LOGOUT_ACTION"]),
    async handleCommand(command) {
      if (command === "logout") {
        let result = await this.LOGOUT_ACTION();
        if (result.code === 1) {
          this.$router.push("/login");
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.head {
  display: flex;
  justify-content: space-between;
  color: #fff;
  h1 {
    margin: 0;
    font-size: 24px;
    img {
      width: 45px;
    }
  }
  .el-dropdown {
    color: #fff;
  }
}
</style>
